﻿@model RH.Web.ViewModels.ProductViewModel
@using RH.Web.ViewModels;
@using RH.Common.Extensions;
@{    
    //RH.Web.ViewModels.ProductViewModel model = (RH.Web.ViewModels.ProductViewModel)ViewBag.Product;
    ZGLModel _ZGLModel = null;

    if (Model != null && Model.ZGLModel != null)
    {
        _ZGLModel = Model.ZGLModel; //.CategoryZGL;
    }
    String _Prefix = AppConstants.UI.DYNAMIC_CONTROL_PREFIX;
}

@if (_ZGLModel != null)
{
    if (_ZGLModel.Group.Count > 0)
    {
        foreach (ZGLModelGroup group in _ZGLModel.Group)
        {             
            <div class="rh-dp-group">
                <div class="rh-group-title">
                    @if (!group.Icon.IsNullOrEmpty())
                    {
                        <div class="pull-left">
                            <img class="ItemGroupIcon" src="@(AppConstants.Directories.PRODUCT_PROPERTY_GROUP_ICONS + "/" + group.Icon)" alt="" title="@group.Name" />
                        </div>
                    }
                    <div class="pull-left">@group.Name</div>
                    <div class="clearfix"></div>                
                </div>
                @foreach (ZGLModelGroupProperty property in group.Property)
                {
                    String controlName = _Prefix + property.Name;
                    MvcHtmlString validationAttributes = ZGLHelper.GenerateValidationAttributes(property);
                    MvcHtmlString validationMessageSpan = MvcHtmlString.Empty;
                    if(validationAttributes != MvcHtmlString.Empty){
                        validationMessageSpan = MvcHtmlString.Create("<span class=\"field-validation-valid\" data-valmsg-for=\"" + controlName + "\" data-valmsg-replace=\"true\"></span>");
                    }
                    if (String.Compare(property.DataType, "BIT", true) != 0) { 
                    <div class="editor-label">
                        @property.Label
                        @if (!property.LabelHint.IsNullOrEmpty())
                        {
                            <div class="rh-label-hint">@property.LabelHint</div>
                        }				        
			        </div>
                    }
			        <div class="editor-field">
                        @if (property.DataType == "BIT") {
                            <label><input type="checkbox" id="@controlName" name="@controlName" value="1"@{if(property.Value.ToBoolean()) {<text> checked</text>}} /> @property.Label</label>
                            @*@Html.CheckBox(controlName, property.Value.ToBoolean())*@
                        }
                        ///Dropdownlist from Static Entry in ZGL
                        else if (property.Option.Count > 0)
                        {
                            <select id="@(controlName)" name="@(controlName)" @validationAttributes class="form-control">
                                <option value="">Please Select</option>
                                @foreach (var option in property.Option)
                                {
                                    <option value="@option.Value" @ZGLHelper.GetSelected(property.Value, option.Value)>@option.Text</option>
                                }
                            </select>
                            @validationMessageSpan
                        }
                        ///Dropdownlist from Database Table
                        else if (!property.ListProvider.IsNullOrEmpty() && !property.ValueColumn.IsNullOrEmpty() && !property.TextColumn.IsNullOrEmpty())
                        {
                            RH.Domain.UtilityDAO dao = new RH.Domain.UtilityDAO();
                            System.Data.DataTable dt = dao.GetLookUpData(property.ListProvider, property.ValueColumn, property.TextColumn);
                            <select id="@(controlName)" name="@(controlName)" @validationAttributes class="form-control">
                                <option value="">Please Select</option>
                                @for (int i = 0; i < dt.Rows.Count; i++)
                                {
                                    System.Data.DataRow row = dt.Rows[i];
                                    <option value="@row[property.ValueColumn]" @ZGLHelper.GetSelected(property.Value, row[property.ValueColumn].ToString())>@row[property.TextColumn]</option>
                                }
                            </select>
                            @validationMessageSpan
                        }
                        ///Textboxes with/without validation
                        else
                        {
                            <input type="text" class="form-control" value="@property.Value.HtmlDecode()" id="@(controlName)" name="@(controlName)" @validationAttributes />
                            @validationMessageSpan
                        }
			        </div>
                }
            </div>
        }
    }
}